<?php
class AdministratorAction extends Action{
	//显示登陆页面
	public function index(){
		$this->display('Index/login');
	}

	//用户登陆
	//登陆成功后设置Adminid,Adminname两个Session变量
	public function login(){
		if(empty($_POST['name'])) {
			$this->error('帐号必须！');
		}elseif (empty($_POST['password'])){
			$this->error('密码必须！');
		}elseif (empty($_POST['verify'])){
			$this->error('验证码必须！');
		}

		if($_SESSION['verify'] != md5($_POST['verify'])) {
			$this->error('验证码错误！');
		}

		$model = M("Administrator");
		$list = $model->where("name = '{$_POST['name']}'")->find();
		if(empty($list)){
			$this->error('账号有误,请重新输入');
		}else if($list['password'] === md5($_POST['password'])){
			Session::set('adminid',$list['id']);
			Session::set('adminname',$list['name']);
			$this->assign('jumpUrl','__GROUP__/Index');
			$this->success('登陆成功');
		}else{
			$this->error('密码有误');
		}
	}

	//注销登陆
	public function logout(){
		Session::destroy();
		$this->assign('jumpUrl','__URL__/index');
		$this->success("注销成功");
	}
	
	// 输出验证码图片
	public function verify(){
		import("ORG.Util.Image");
		Image::buildImageVerify();
	}
}
?>
